package aerouacmsla.interfazDeUsuario;
import aerouacmsla.entidad.Usuario;
import aerouacmsla.procedimientos.BDConexion;
import aerouacmsla.procedimientos.GeneradorIdes;
import java.awt.Color;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import javax.swing.ImageIcon;
/**
 *
 * @author luis
 */
public class VentanaNuevoUsuario extends javax.swing.JDialog {

    private Usuario usuarioActual = new Usuario();
    private BDConexion miConexion;
    private Object originalBorder;
    private int Anno;
    private int Mes;
    private int Dia;

    public BDConexion getMiConexion() {
        return miConexion;
    }

    public int getAnno() {
        return Anno;
    }

    public void setAnno(int Anno) {
        this.Anno = Anno;
    }

    public int getDia() {
        return Dia;
    }

    public void setDia(int Dia) {
        this.Dia = Dia;
    }

    public int getMes() {
        return Mes;
    }

    public void setMes(int Mes) {
        this.Mes = Mes;
    }


    public void setMiConexion(BDConexion miConexion) {
        this.miConexion = miConexion;
    }

    /** Creates new form VentanaNuevoUsuario */
    public VentanaNuevoUsuario() {
        initComponents();
        setComboAnno();
        setModal(true);
        jLabel20.setVisible(false);
        jLabel21.setVisible(false);
    }
     public boolean separarFecha(String fechaCompleta){
        String[] separado = fechaCompleta.split("-");
        if (separado.length == 3) {
            setAnno(Integer.parseInt(separado[0]));
            setMes(Integer.parseInt(separado[1]));
            setDia(Integer.parseInt(separado[2]));
            return true;
        }
        return false;
    }

    public VentanaNuevoUsuario(BDConexion miConexion) {
        initComponents();
        setMiConexion(miConexion);
        setComboAnno();
        setModal(true);
        
        jLabel20.setVisible(false);
        jLabel21.setVisible(false);

        getMiConexion().sendSQLQuery("SELECT nombre_cargo FROM cargo");
        cargoUsuario.setModel(new DefaultComboBoxModel(getMiConexion().getLastResultSetColumnStrings("nombre_cargo")));
    }
    public VentanaNuevoUsuario(Usuario usuario, BDConexion miConexion) {
        initComponents();
        jLabel20.setText("Disponible");
        jLabel21.setText("Claves iguales");
        jLabel21.setForeground(new Color(0,153,0));
        jLabel20.setVisible(false);
        setMiConexion(miConexion);
        setUsuarioActual(usuario);
        setComboAnno();
        setModal(true);
        getMiConexion().sendSQLQuery("SELECT nombre_cargo FROM cargo");
        cargoUsuario.setModel(new DefaultComboBoxModel(getMiConexion().getLastResultSetColumnStrings("nombre_cargo")));
        jButton1.setText("Modificar");
        usernameUsuario.setEditable(false);
        usernameUsuario.setText(getUsuarioActual().getNombreDeUsuario());
        nombreUsuarioNuevo.setText(getUsuarioActual().getNombre());
        apellidoPaternoUsuario.setText(getUsuarioActual().getApellidoPaterno());
        apellidoMaternoUsuario.setText(getUsuarioActual().getApellidoMaterno());
        telefonoUsuario.setText(getUsuarioActual().getTelefono());
        paisUsuario.setText(getUsuarioActual().getPais());
        estadoUsuario.setText(getUsuarioActual().getEstado());
        ciudadUsuario.setText(getUsuarioActual().getCiudad());
        calleUsuario.setText(getUsuarioActual().getCalle());
        coloniaUsuario.setText(getUsuarioActual().getColonia());
        usernameUsuario.setText(getUsuarioActual().getNombreDeUsuario());
        clave1.setText(getUsuarioActual().getClave());
        clave2.setText(getUsuarioActual().getClave());
        rfcUsuario.setText(getUsuarioActual().getRfc());
        correoElectronicoUsuario.setText(getUsuarioActual().getCorreoElectronico());
        codigoPostalUsuario.setText(getUsuarioActual().getCodigoPostal());
        telefonoDeCasaUsuario.setText(getUsuarioActual().getTelefonoCasa());
        faxUsuario.setText(getUsuarioActual().getFax());
        if(separarFecha(getUsuarioActual().getFechaDeNacimiento())){
            comboAnno.setSelectedItem(getAnno());
            comboMes.setSelectedIndex(getMes()-1);
            comboDia.setSelectedIndex(getDia()-1);
        }
        

    }

    private void setComboAnno(){
        Calendar fecha = new GregorianCalendar();
        int annoActual = fecha.get(Calendar.YEAR);
        Object objetosComboAnno[] = null;
        for(int i=annoActual-18; i>=annoActual-35; i--){
            objetosComboAnno = addObject(objetosComboAnno, i);
        }
        comboAnno.setModel(new DefaultComboBoxModel(objetosComboAnno));
    }

    public Object[] addObject(Object objeto[], Object newObject){
        Object[] retorno = null;
        if (objeto != null ){
            retorno = new Object[objeto.length + 1];
            for(int i=0; i<objeto.length; i++){
                retorno[i] = objeto[i];
            }
        }
        else retorno = new Object[1];
        retorno[retorno.length-1] = newObject;
        return retorno;
    }

     public boolean validarTam (String cadena, int tamano){
        if(cadena.length()<=tamano){
            return false;
        }
        return true;
    }

    public Usuario getUsuarioActual() {
        return usuarioActual;
    }

    public void setUsuarioActual(Usuario usuarioActual) {
        this.usuarioActual = usuarioActual;
    }

    public Object getOriginalBorder(){
        return originalBorder;
    }
    public void setOriginalBorder(Object border){
        this.originalBorder = border;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        nombreUsuarioNuevo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        apellidoPaternoUsuario = new javax.swing.JTextField();
        apellidoMaternoUsuario = new javax.swing.JTextField();
        comboDia = new javax.swing.JComboBox();
        comboMes = new javax.swing.JComboBox();
        comboAnno = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        paisUsuario = new javax.swing.JTextField();
        estadoUsuario = new javax.swing.JTextField();
        ciudadUsuario = new javax.swing.JTextField();
        coloniaUsuario = new javax.swing.JTextField();
        calleUsuario = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        usernameUsuario = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        cargoUsuario = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        clave1 = new javax.swing.JPasswordField();
        clave2 = new javax.swing.JPasswordField();
        jLabel14 = new javax.swing.JLabel();
        telefonoUsuario = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        telefonoDeCasaUsuario = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        faxUsuario = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        codigoPostalUsuario = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        rfcUsuario = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        correoElectronicoUsuario = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Usuario");
        setIconImage(new ImageIcon(getClass().getResource("/Recursos/IconoUsuario32px.png")).getImage());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Campos Obligatorios"));

        jLabel1.setText("Nombre");

        jLabel2.setText("Apellido Paterno");

        jLabel3.setText("Apellido Materno");

        jLabel4.setText("Fecha de nacimiento");

        comboDia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        comboMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));
        comboMes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboMesItemStateChanged(evt);
            }
        });

        comboAnno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010" }));
        comboAnno.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboAnnoItemStateChanged(evt);
            }
        });

        jLabel5.setText("Pais");

        jLabel6.setText("Estado");

        jLabel7.setText("Ciudad");

        jLabel8.setText("Colonia");

        jLabel9.setText("Calle");

        jLabel10.setText("Nombre Usuario");

        usernameUsuario.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                usernameUsuarioFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                usernameUsuarioFocusLost(evt);
            }
        });

        jLabel11.setText("Clave");

        jLabel12.setText("Cargo");

        cargoUsuario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Usuario", "Administrador" }));

        jLabel13.setText("Confirmar clave");

        clave2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                clave2FocusLost(evt);
            }
        });

        jLabel14.setText("Telefono");

        jLabel20.setForeground(new java.awt.Color(0, 153, 0));
        jLabel20.setText("Disponibilidad");

        jLabel21.setText("Verificacion");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel14)
                            .addComponent(jLabel1)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(paisUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(telefonoUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(comboDia, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboMes, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboAnno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(apellidoMaternoUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(apellidoPaternoUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addComponent(nombreUsuarioNuevo, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(estadoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ciudadUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(calleUsuario)
                            .addComponent(cargoUsuario, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(clave2)
                            .addComponent(clave1)
                            .addComponent(usernameUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                            .addComponent(coloniaUsuario)
                            .addComponent(jLabel20, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel21, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addGap(30, 30, 30))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(nombreUsuarioNuevo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(apellidoPaternoUsuario))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(apellidoMaternoUsuario))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 13, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(comboDia)
                        .addComponent(comboMes)
                        .addComponent(comboAnno)))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(telefonoUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(estadoUsuario)
                        .addComponent(ciudadUsuario)
                        .addComponent(paisUsuario)))
                .addGap(17, 17, 17)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(calleUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(coloniaUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(usernameUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(clave1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(clave2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel21)
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(cargoUsuario))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Campos opcionales"));

        jLabel15.setText("Telefono de Casa");

        jLabel16.setText("Fax");

        jLabel17.setText("Codigo Postal");

        jLabel18.setText("RFC");

        jLabel19.setText("Correo Electronico");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel18)
                    .addComponent(jLabel16)
                    .addComponent(jLabel15)
                    .addComponent(jLabel17)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addGap(9, 9, 9)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(correoElectronicoUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                    .addComponent(rfcUsuario)
                    .addComponent(codigoPostalUsuario)
                    .addComponent(faxUsuario)
                    .addComponent(telefonoDeCasaUsuario))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(telefonoDeCasaUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(faxUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(codigoPostalUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(rfcUsuario))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(correoElectronicoUsuario))
                .addGap(54, 54, 54))
        );

        jButton1.setText("Crear");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked

        if(jLabel20.getText().equals("Disponible")&&jLabel21.getText().equals("Claves iguales")){
        String clave = new String(clave1.getPassword());
        String claveComprobacion = new String(clave2.getPassword());
        if (clave.equals(claveComprobacion))
         if(!nombreUsuarioNuevo.getText().isEmpty()&&
           !apellidoPaternoUsuario.getText().isEmpty()&&
           !apellidoMaternoUsuario.getText().isEmpty()&&
           !telefonoUsuario.getText().isEmpty()&&
            !paisUsuario.getText().isEmpty()&&
            !estadoUsuario.getText().isEmpty()&&
             !ciudadUsuario.getText().isEmpty()&&
              !calleUsuario.getText().isEmpty()&&
               !coloniaUsuario.getText().isEmpty()&&
                !usernameUsuario.getText().isEmpty()&&
                !clave1.getPassword().toString().isEmpty()&&
                !clave2.getPassword().toString().isEmpty()

          ){

              boolean excedecaracteres[] = {
                  validarTam(nombreUsuarioNuevo.getText(),15),
                  validarTam(apellidoPaternoUsuario.getText(),15),
                  validarTam(apellidoMaternoUsuario.getText(),15),
                  validarTam(telefonoUsuario.getText(),18),
                  validarTam(paisUsuario.getText(),15),
                  validarTam(estadoUsuario.getText(),15),
                  validarTam(ciudadUsuario.getText(),20),
                  validarTam(calleUsuario.getText(),15),
                  validarTam(coloniaUsuario.getText(),15),
                  validarTam(usernameUsuario.getText(),15),
                  validarTam(telefonoDeCasaUsuario.getText(),15),
                  validarTam(faxUsuario.getText(),18),
                  validarTam(codigoPostalUsuario.getText(),8),
                  validarTam(rfcUsuario.getText(),13),
                  validarTam(correoElectronicoUsuario.getText(),50),
                  validarTam(new String(clave1.getPassword()),12),
                  validarTam(new String(clave2.getPassword()),12)
              };

              if( excedecaracteres[0] || excedecaracteres[1] ||
                  excedecaracteres[2] || excedecaracteres[3] ||
                  excedecaracteres[4] || excedecaracteres[5] ||
                  excedecaracteres[6] || excedecaracteres[7] ||
                  excedecaracteres[8] || excedecaracteres[9] ||
                  excedecaracteres[10] || excedecaracteres[11] ||
                  excedecaracteres[12] || excedecaracteres[13] ||
                  excedecaracteres[14] || excedecaracteres[15] ||
                  excedecaracteres[16]){
            boolean someError = false;
            String mensajeDeError = "";
            if (excedecaracteres[0]){
                someError = true;
                mensajeDeError += "El campo 'Nombre' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Nombre");
            }
            if (excedecaracteres[1]){
                someError = true;
                mensajeDeError += "El campo 'Apellido Paterno' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Apellido Paterno");
            }
            if (excedecaracteres[2]){
                someError = true;
                mensajeDeError += "El campo 'Apellido Materno' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Apellido Materno");
            }
            if (excedecaracteres[3]){
                someError = true;
                mensajeDeError += "El campo 'Telefono' debe ser menor o igual a 20 caracteres\n";
                System.out.println("exede numero de caracteres en Telefono");
            }
            if (excedecaracteres[4]){
                someError = true;
                mensajeDeError += "El campo 'Pais' debe ser menor o igual a 15 caracteres\n";
                System.out.println("exede numero de caracteres en Pais");
            }
            if (excedecaracteres[5]){
                someError = true;
                mensajeDeError += "El campo 'Estado' debe ser menor o igual a 15 caracteres\n";
                System.out.println("exede numero de caracteres en Estado");
            }
            if (excedecaracteres[6]){
                someError = true;
                mensajeDeError += "El campo 'Ciudad' debe ser menor o igual a 15 caracteres\n";
                System.out.println("exede numero de caracteres en Ciudad");
            }
            if (excedecaracteres[7]){
                someError = true;
                mensajeDeError += "El campo 'Calle' debe ser menor o igual a 15 caracteres\n";
                System.out.println("exede numero de caracteres en Calle");
            }
            if (excedecaracteres[8]){
                someError = true;
                mensajeDeError += "El campo 'Colonia' debe ser menor o igual a 15 caracteres\n";
                System.out.println("exede numero de caracteres en Colonia");
            }
            if (excedecaracteres[9]){
                someError = true;
                mensajeDeError += "El campo 'Nombre de Usuario' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Nombre Usuario");
            }
            if (excedecaracteres[10]){
                someError = true;
                mensajeDeError += "El campo 'Telefono Casa' debe ser menor o igual a 20 caracteres\n";
                System.out.println("exede numero de caracteres en Telefono de Casa");
            }
            if (excedecaracteres[11]){
                someError = true;
                mensajeDeError += "El campo 'Fax' debe ser menor o igual a 20 caracteres\n";
                System.out.println("exede numero de caracteres en Fax");
            }
            if (excedecaracteres[12]){
                someError = true;
                mensajeDeError += "El campo 'Codigo Postal' debe ser menor o igual a 10 caracteres\n";
                System.out.println("exede numero de caracteres en Codigo Postal");
            }
            if (excedecaracteres[13]){
                someError = true;
                mensajeDeError += "El campo 'RFC' debe ser menor o igual a 20 caracteres\n";
                System.out.println("exede numero de caracteres en RFC");
            }
            if (excedecaracteres[14]){
                someError = true;
                mensajeDeError += "El campo 'Correo Electronico' debe ser menor o igual a 50 caracteres\n";
                System.out.println("exede numero de caracteres en Correo Electronico");
            }
            if (excedecaracteres[15]){
                someError = true;
                mensajeDeError += "El campo 'Clave' debe ser menor o igual a 12 caracteres\n";
                System.out.println("exede numero de caracteres en Clave");
            }
            if (someError)
                JOptionPane.showMessageDialog(this,
                 mensajeDeError,
                 "Error de datos",
                 JOptionPane.ERROR_MESSAGE);


         }else{

                  getUsuarioActual().setNombre(nombreUsuarioNuevo.getText());
                  getUsuarioActual().setApellidoPaterno(apellidoPaternoUsuario.getText());
                  getUsuarioActual().setApellidoMaterno(apellidoMaternoUsuario.getText());
                  getUsuarioActual().setTelefono(telefonoUsuario.getText());
                  getUsuarioActual().setPais(paisUsuario.getText());
                  getUsuarioActual().setEstado(estadoUsuario.getText());
                  getUsuarioActual().setCiudad(ciudadUsuario.getText());
                  getUsuarioActual().setCalle(calleUsuario.getText());
                  getUsuarioActual().setColonia(coloniaUsuario.getText());
                  getUsuarioActual().setNombreDeUsuario(usernameUsuario.getText());
                  getUsuarioActual().setClave(clave);
                  getUsuarioActual().setRfc(rfcUsuario.getText());
                  getUsuarioActual().setCorreoElectronico(correoElectronicoUsuario.getText());
                  getUsuarioActual().setCodigoPostal(codigoPostalUsuario.getText());
                  getUsuarioActual().setTelefonoCasa(telefonoDeCasaUsuario.getText());
                  getUsuarioActual().setFax(faxUsuario.getText());
                  getUsuarioActual().setFechaDeNacimiento(
                          comboAnno.getSelectedItem().toString() +
                          "-" + (comboMes.getSelectedIndex()+1) +
                          "-" + comboDia.getSelectedItem().toString());
                  String cargo = cargoUsuario.getSelectedItem().toString();

                  getMiConexion().sendSQLQuery("SELECT id_cargo FROM cargo WHERE nombre_cargo ='" + cargo + "';");
                try {
                    if (getMiConexion().getResultado().next()) {
                        int idCargo = getMiConexion().getResultado().getInt("id_cargo");
                        getUsuarioActual().setCargo(idCargo);
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(VentanaNuevoUsuario.class.getName()).log(Level.SEVERE, null, ex);
                }

                 GeneradorIdes GI = new GeneradorIdes(getUsuarioActual().getNombre(), getUsuarioActual().getApellidoPaterno(), getUsuarioActual().getApellidoMaterno(), getUsuarioActual().getFechaDeNacimiento());
                  if (jButton1.getText().equalsIgnoreCase("Registrar")) {
                      usuarioActual.setNombreDeUsuario(GI.getId());
                      for (;;) {
                          try {
                              if (getMiConexion().sendSQLQuery("SELECT * FROM usuarios WHERE nombre_usuario = '" + getUsuarioActual().getNombreDeUsuario() + "';").next()) {
                                  usuarioActual.setNombreDeUsuario(GI.siguienteId());
                              } else {
                                  break;
                              }
                          } catch (SQLException ex) {
                              Logger.getLogger(PanelAdministrarCiudades.class.getName()).log(Level.SEVERE, null, ex);
                          }
                      }
                  }

                  String SQL = null;
            if(jButton1.getText().equalsIgnoreCase("Crear")){
                   SQL = "INSERT INTO usuarios VALUES ('"+ getUsuarioActual().getNombre() +"', '" + getUsuarioActual().getApellidoPaterno()
                    + "', '" + getUsuarioActual().getApellidoMaterno() + "', '" + getUsuarioActual().getCalle() +"', '" + getUsuarioActual().getColonia() + "', '"
                    + getUsuarioActual().getCiudad() + "', '"+ getUsuarioActual().getEstado() + "', '"+ getUsuarioActual().getPais() + "', '"
                    + getUsuarioActual().getCodigoPostal() + "', '"+ getUsuarioActual().getTelefono() + "', '"+ getUsuarioActual().getTelefonoCasa() + "', '" +
                    getUsuarioActual().getFax()+ "', '" + getUsuarioActual().getNombreDeUsuario() + "', '"+ getUsuarioActual().getClave() +"', "+ getUsuarioActual().getCargo() +", '"
                    + getUsuarioActual().getCorreoElectronico() +"', '"+ getUsuarioActual().getRfc() +"', '"+ getUsuarioActual().getFechaDeNacimiento() +"');";
            }
            else{
                    SQL = " UPDATE usuarios SET nombre = '" +
                        getUsuarioActual().getNombre() +"' , apellido_paterno ='"+getUsuarioActual().getApellidoPaterno() +"', apellido_materno = '" +
                        getUsuarioActual().getApellidoMaterno()+"', calle= '"+getUsuarioActual().getCalle()+"',colonia = '"+getUsuarioActual().getColonia()+
                        "',ciudad = '"+getUsuarioActual().getCiudad()+"',estado = '"+getUsuarioActual().getEstado()+"',pais = '"+getUsuarioActual().getPais()+
                        "',codigo_postal = '"+getUsuarioActual().getCodigoPostal()+"', telefono = '"+getUsuarioActual().getTelefono() +"', telefono_casa = '"+getUsuarioActual().getTelefonoCasa()+
                        "',fax = '"+ getUsuarioActual().getFax()+"',clave = '"+ getUsuarioActual().getClave()+ "', id_cargo = '"+ getUsuarioActual().getCargo()+"',rfc = '"
                        +getUsuarioActual().getRfc() +"', correo_electronico = '"+getUsuarioActual().getCorreoElectronico()+"',  fecha_nacimiento = '"+
                        getUsuarioActual().getFechaDeNacimiento()+"' WHERE nombre_usuario = '" + getUsuarioActual().getNombreDeUsuario() +"';";
                }
            getMiConexion().sendSQL(SQL);
            JOptionPane.showMessageDialog(this,
                 "El usuario ha sido registrado exitosamente",
                 "Usuario Registrado Exitosamente",
                 JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
    }
       }else JOptionPane.showMessageDialog(this,
                 "Es necesario llenar todos los campos obligatorios",
                 "Error de datos",
                 JOptionPane.ERROR_MESSAGE);
        else JOptionPane.showMessageDialog(this,
                 "La confirmacion de la clave no es correcta",
                 "Error de datos",
                 JOptionPane.ERROR_MESSAGE);
        }
        else
        JOptionPane.showMessageDialog(this,
                 "Verifica el nombre de usuario y clave",
                 "Error de datos",
                 JOptionPane.ERROR_MESSAGE);


   
 
    }//GEN-LAST:event_jButton1MouseClicked

    private void comboMesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboMesItemStateChanged
        String mes = comboMes.getSelectedItem().toString();
        int diaSeleccionado = comboDia.getSelectedIndex();
        int mesInt = 0;
        if (mes.equalsIgnoreCase("enero"))
            mesInt = 1;
        else if (mes.equalsIgnoreCase("febrero"))
            mesInt = 2;
        else if (mes.equalsIgnoreCase("marzo"))
            mesInt = 3;
        else if (mes.equalsIgnoreCase("abril"))
            mesInt = 4;
        else if (mes.equalsIgnoreCase("mayo"))
            mesInt = 5;
        else if (mes.equalsIgnoreCase("junio"))
            mesInt = 6;
        else if (mes.equalsIgnoreCase("julio"))
            mesInt = 7;
        else if (mes.equalsIgnoreCase("agosto"))
            mesInt = 8;
        else if (mes.equalsIgnoreCase("septiembre"))
            mesInt = 9;
        else if (mes.equalsIgnoreCase("octubre"))
            mesInt = 10;
        else if (mes.equalsIgnoreCase("noviembre"))
            mesInt = 11;
        else if (mes.equalsIgnoreCase("diciembre"))
            mesInt = 12;
        Object dias[] = null;
        switch(mesInt){
            case 1:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 2:
                dias = null;
                int annio =  Integer.parseInt(comboAnno.getSelectedItem().toString());
                int biciesto = 28;
                if (annio%4 == 0) biciesto = 29;
                for (int i = 1; i <= biciesto; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 3: 
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 4: 
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 5: 
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 6:
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 7:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 8:
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 9:
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 10: 
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 11: 
                dias = null;
                for (int i = 1; i <= 30; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
            case 12: 
                dias = null;
                for (int i = 1; i <= 31; i++)
                    dias = addObject(dias, i);
                comboDia.setModel(new DefaultComboBoxModel(dias));
                if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
                break;
        }
    }//GEN-LAST:event_comboMesItemStateChanged

    private void comboAnnoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboAnnoItemStateChanged
        if (comboMes.getSelectedItem().toString().equalsIgnoreCase("febrero")){
            int diaSeleccionado = Integer.parseInt(comboDia.getSelectedItem().toString());
            Object[] dias = null;
            int annio = Integer.parseInt(comboAnno.getSelectedItem().toString());
            if (annio%4!=0) {
                for (int i=1; i<=28; i++){
                    dias = addObject(dias, i);
                }
            }
            else
                for (int i=1; i<=29; i++){
                    dias = addObject(dias, i);
                }
            comboDia.setModel(new DefaultComboBoxModel(dias));
            if (comboDia.getItemCount() > diaSeleccionado)
                comboDia.setSelectedIndex(diaSeleccionado);
        }
    }//GEN-LAST:event_comboAnnoItemStateChanged

    private void usernameUsuarioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_usernameUsuarioFocusGained
        setOriginalBorder(usernameUsuario.getBorder());
        usernameUsuario.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(255, 0, 0)));
    }//GEN-LAST:event_usernameUsuarioFocusGained

    private void usernameUsuarioFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_usernameUsuarioFocusLost
        usernameUsuario.setBorder((Border) getOriginalBorder());
        try {
                              if(getMiConexion().sendSQLQuery("SELECT * FROM usuarios WHERE nombre_usuario= '" + usernameUsuario.getText() + "';").next()) {
                                  jLabel20.setForeground(new Color(255,0,0));
                                  jLabel20.setText("No esta disponible");
                                  jLabel20.setVisible(true);
                              } else {
                                  jLabel20.setForeground(new Color(0,153,0));
                                  jLabel20.setText("Disponible");
                                  jLabel20.setVisible(true);
                              }
                          } catch (SQLException ex) {
                              Logger.getLogger(VentanaNuevoUsuario.class.getName()).log(Level.SEVERE, null, ex);
                          }
       // if(getMiConexion().sendSQLQuery("SELECT * FROM usuarios WHERE nombre_usuario= '" + usernameUsuario.getText() + "';").next()){

    }//GEN-LAST:event_usernameUsuarioFocusLost

    private void clave2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_clave2FocusLost
        String clave=new String(clave1.getPassword());
        String confirmarClave=new String(clave2.getPassword());
        if(clave.equals(confirmarClave)){
            jLabel21.setForeground(new Color(0,153,0));
            jLabel21.setText("Claves iguales");
            jLabel21.setVisible(true);
        }else{
            jLabel21.setForeground(new Color(255,0,0));
            jLabel21.setText("Claves diferentes, verifiquelo");
            jLabel21.setVisible(true);
        }
        
    }//GEN-LAST:event_clave2FocusLost

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaNuevoUsuario().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField apellidoMaternoUsuario;
    private javax.swing.JTextField apellidoPaternoUsuario;
    private javax.swing.JTextField calleUsuario;
    private javax.swing.JComboBox cargoUsuario;
    private javax.swing.JTextField ciudadUsuario;
    private javax.swing.JPasswordField clave1;
    private javax.swing.JPasswordField clave2;
    private javax.swing.JTextField codigoPostalUsuario;
    private javax.swing.JTextField coloniaUsuario;
    private javax.swing.JComboBox comboAnno;
    private javax.swing.JComboBox comboDia;
    private javax.swing.JComboBox comboMes;
    private javax.swing.JTextField correoElectronicoUsuario;
    private javax.swing.JTextField estadoUsuario;
    private javax.swing.JTextField faxUsuario;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField nombreUsuarioNuevo;
    private javax.swing.JTextField paisUsuario;
    private javax.swing.JTextField rfcUsuario;
    private javax.swing.JTextField telefonoDeCasaUsuario;
    private javax.swing.JTextField telefonoUsuario;
    private javax.swing.JTextField usernameUsuario;
    // End of variables declaration//GEN-END:variables



}
